package com.ruoyi.camp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.camp.domain.CAppointment;
import com.ruoyi.camp.service.ICAppointmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 营地预约Controller
 * 
 * @author ruoyi
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/camp/appointment")
public class CAppointmentController extends BaseController
{
    @Autowired
    private ICAppointmentService cAppointmentService;

    /**
     * 查询营地预约列表
     */
    @PreAuthorize("@ss.hasPermi('camp:appointment:list')")
    @GetMapping("/list")
    public TableDataInfo list(CAppointment cAppointment)
    {
        startPage();
        List<CAppointment> list = cAppointmentService.selectCAppointmentList(cAppointment);
        return getDataTable(list);
    }

    /**
     * 导出营地预约列表
     */
    @PreAuthorize("@ss.hasPermi('camp:appointment:export')")
    @Log(title = "营地预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CAppointment cAppointment)
    {
        List<CAppointment> list = cAppointmentService.selectCAppointmentList(cAppointment);
        ExcelUtil<CAppointment> util = new ExcelUtil<CAppointment>(CAppointment.class);
        util.exportExcel(response, list, "营地预约数据");
    }

    /**
     * 获取营地预约详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:appointment:query')")
    @GetMapping(value = "/{appointmentid}")
    public AjaxResult getInfo(@PathVariable("appointmentid") String appointmentid)
    {
        return success(cAppointmentService.selectCAppointmentByAppointmentid(appointmentid));
    }

    /**
     * 新增营地预约
     */
    @PreAuthorize("@ss.hasPermi('camp:appointment:add')")
    @Log(title = "营地预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CAppointment cAppointment)
    {
        return toAjax(cAppointmentService.insertCAppointment(cAppointment));
    }

    /**
     * 修改营地预约
     */
    @PreAuthorize("@ss.hasPermi('camp:appointment:edit')")
    @Log(title = "营地预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CAppointment cAppointment)
    {
        return toAjax(cAppointmentService.updateCAppointment(cAppointment));
    }

    /**
     * 删除营地预约
     */
    @PreAuthorize("@ss.hasPermi('camp:appointment:remove')")
    @Log(title = "营地预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{appointmentids}")
    public AjaxResult remove(@PathVariable String[] appointmentids)
    {
        return toAjax(cAppointmentService.deleteCAppointmentByAppointmentids(appointmentids));
    }
}
